#coding:utf8
'''
Created on 2014-9-17

@author: root
'''
from flask import render_template

from django.contrib import admin
from models import *
from floating_platen.util import *
from example.app_models.widgets import CKTextAreaWidget, TinyMCETextAreaWidget

class NewsAdmin(admin.ModelAdmin):
    list_display = ('id','title','date')
#     search_fields = ['name','id']
    class Media:
            js = ('/static/plugins/tinymce/js/tinymce/tinymce.min.js',
                  '/static/scripts/textareas.js',
                  )
    formfield_overrides = {
            models.TextField: {'widget': TinyMCETextAreaWidget},
        }

    def save_model(self, request, obj, form, change):
        # 自定义操作
        obj.content = obj.content.replace('../../../..','http://temp.tg.ugolang.com')
        obj.save()
        url = '%s/%s/%s'%(DOMAIN,'show/new',obj.id)
        obj.url = url
        obj.save()
#         try:
#             kw = KeyWord.objects.get(key=obj.key_word)
#         except:
#             kw = KeyWord(key=obj.key_word,url=url)
#             kw.save()

class KeyWordAdmin(admin.ModelAdmin):
    list_display = ('id','key','url')
    
    
admin.site.register(News, NewsAdmin)
admin.site.register(KeyWord, KeyWordAdmin)


